package com.jaccount.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class UsrCheckImpl implements IUsrCheck {

	public UsrCheckImpl() {
		super();
	}

	public void setDataSourceName(String newName) {

	}

	@Override
	public boolean isValid(String id, String password) {
		String url = "jdbc:mysql://localhost:3306/jaccount";
		String username = "root";
		String passwd = "applelqy";
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection(url, username, passwd);

			String query = "select * from jaccount where name = '" + id
					+ "' and password = '" + password+ "'";
			statement = connection.createStatement();
			resultSet = statement.executeQuery(query);
			if (resultSet.next())
				return true;
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally{
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return false;
	}
	

	private Connection connection;
	private Statement statement;
	private ResultSet resultSet;

}
